package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.constant.TransferAccountsPayStatusEnum;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.hr.example.TransferAccountsBatchExample.*;

/**
 * 转账批次
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class TransferAccountsBatchQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = "批次名/申请人/用工单位")
    private String selectName;

    @ApiParam(value = "审批状态：1：审批中 2：已通过 3：已驳回 4：抄送我")
    private Integer approveStatus;

    @ApiParam(value = N_CREATE_USER_NAME, example = E_CREATE_USER_NAME)
    @Length(max = 50)
    private String createUserName;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = "用工单位id集合")
    private List<String> companyIdList;

    @ApiParam(value = N_TYPE, example = E_TYPE)
    private Integer type;

    @ApiParam(value = N_SECOND_TYPE, example = E_SECOND_TYPE)
    private Integer secondType;

    @ApiParam(value = N_THIRD_PARTY_INTERIOR_BATCH_ID, example = E_THIRD_PARTY_INTERIOR_BATCH_ID)
    @Length(max = 200)
    private String thirdPartyInteriorBatchId;

    @ApiParam(value = N_ORDER_TITLE, example = E_ORDER_TITLE)
    @Length(max = 64)
    private String orderTitle;

    @ApiParam(value = N_SUBJECT_STATUS, example = E_SUBJECT_STATUS)
    private Integer subjectStatus;

    @ApiParam(value = N_PAY_STATUS, example = E_PAY_STATUS, allowableValues = TransferAccountsPayStatusEnum.VALUES_STR)
    private Integer payStatus;

    @ApiParam(value = N_ISSUE_USER_NAME, example = E_ISSUE_USER_NAME)
    @Length(max = 20)
    private String issueUserName;

    @ApiParam(value = N_ISSUE_ACCOUNT_NAME, example = E_ISSUE_ACCOUNT_NAME)
    @Length(max = 100)
    private String issueAccountName;

    @ApiParam(value = N_PAY_TYPE, example = E_PAY_TYPE)
    private Integer payType;

    @ApiParam(value = N_IS_DISPOSE, example = E_IS_DISPOSE)
    private Boolean isDispose;

    @ApiParam(value = "不要的业务状态, 可以传多个， 数组格式")
    private List<String> notSubjectStatusList;

    @ApiParam(value = "不要的业务状态, 可以传多个， 数组格式")
    private String notSubjectStatusListStr;

    /**
     * 创建时间查询范围
     */
    @ApiParam(value = N_GMT_CREATE_START, example = E_GMT_CREATE_START)
    private Date gmtCreateStart;
    @ApiParam(value = N_GMT_CREATE_END, example = E_GMT_CREATE_END)
    private Date gmtCreateEnd;




    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public TransferAccountsBatchQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

